package com.second.app.thread.p_c_callwait;

/**
 * @Author soul yzg
 * @Date 2021/1/26 7:18
 * 努力学习 天天进步
 */
public class Run {
    public static void main(String[] args) throws InterruptedException {

        String lock = new String("");
        Produce produce = new Produce(lock);
        Consumer consumer = new Consumer(lock);

        ThreadP[] threadPArray = new ThreadP[2];

        ThreadC[] threadCArray = new ThreadC[2];
        for (int i = 0; i < 2; i++) {
            threadPArray[i] = new ThreadP(produce);
            threadPArray[i].setName("生产者" + (i + 1));

            threadCArray[i] = new ThreadC(consumer);
            threadCArray[i].setName("消费者" + (i + 1));
            threadPArray[i].start();
            threadCArray[i].start();
        }
        Thread.sleep(5000);
        Thread[] threadArray = new Thread[(Thread.currentThread().getThreadGroup().activeCount())];
        Thread.currentThread().getThreadGroup().enumerate(threadArray);
        for (Thread thread : threadArray) {
            System.out.println(thread.getName() + " " + thread.getState());
        }
    }
}
